<!--processed-->
<link rel="stylesheet" href="/views/resolution/detail/tmp.css">
<section id="resolution-detail">
    <div class="breadcrumb fx-row-s">
        <i class="back iconfont icon-fanhui1" id="back"></i>
        <span>Resolution</span>
        <span class="interval">/</span>
        <span>Detail</span>
    </div>
    <div class="feat-grid">
        <div class="row">
            <div class="left col-sm-14">
                <div class="left-head">
                    <!--模板填充-->
                    <span class="time"></span>
                    <span><label>Payment from：</label><span  class="pay"></span></span>
                    <span><label>Transcation amount：</label> <span class="money-tran"></span></span>
                    <button id="update" class="btn-e">Update</button>
                    <button id="translation" class="btn-e">Re Translation</button>
                    <!--<span><label>Disputed amount：</label> <span class="money"></span> </span>-->
                </div>
                <div class="left-title mt10">
                    <h4 data-name="reason">Item not received</h4>
                    <p>Case ID: <span data-name="disputeId">No Case</span></p>
                </div>
                <div class="left-content mt30">

                </div>

                <div class="left-message">
                    <div class="tr">
                        <button id="quote" class="btn-d hide">Replacement item offer</button>
                        <button id="part" class="btn-d  hide">Partial refund offer</button>
                        <button id="refund" class="btn-d">Full Refund</button>
                        <button id="refund-all" class="btn-d hide mt5">Full refund offer with item return</button>
                    </div>
                    <section data-name="aiReplyTemp" class="com-select w12 fl" style="width:250px;margin-top: 5px;">
                        <div class="sel-item">
                            <input id="selectedIntent" class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="Select a Intent"/>
                            <!-- <input name="businessUnitId" type="hidden" value=""> -->
                            <i class="sel-icon"></i>
                        </div>
                        <ul id="aiReplyTemp" class="sel-content">
                            <!--回复模板填充-->
                        </ul>
                    </section>
                    <textarea name="" id="sendInfoMsg" placeholder="Send a friendly message to the buyer"></textarea>
                    <!--<div id="sendInfoMsg"></div>-->

                    <!--模板选择-->
                    <div id="resolutionTmpSend" data-name="comRadio" class="com-radio" style="width: 100%;">

                    </div>

                    <div class="row mt10">
                        <div class="col-sm-14">
                            <!--<section id="isCheck" data-name="com-check" class="com-check">
                                <label>
                                    <i data-name="checkStyle" class="check-box"></i>
                                    <input type="checkbox" value="1">
                                </label>
                            </section>-->
                            <span>Ask the buyer to send a photo of the item to：</span>
                            <!--<input name="sendInfoEmail" autocomplete="on" type="text" class="form-input" placeholder="邮箱地址">-->
                            <div class="form-group-b">
                                <section data-name="sendInfoEmail" class="com-select">
                                    <div class="sel-item">
                                        <input id="emailInput" class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="e-mail address"/>
                                        <input name="sendInfoEmail" type="hidden" value="">
                                    </div>
                                    <ul class="sel-content" id="emailList">
                                    </ul>
                                </section>
                            </div>
                        </div>
                        <div class="col-sm-10 tr">
                            <button type="button" class="btn-b" id="clearTmp">
                                clear
                            </button>
                            <button type="button" class="btn-a" id="sendInfo">
                                <i class="send-animate"><span class="send-main"></span></i>
                                <span class="send-text">Send Message</span>
                            </button>
                        </div>
                    </div>

                </div>
                <h4 class="left-offer-head mt40">Offer Action Logs</h4>
                <ul class="left-offer mt10">
                    <!--填充offer信息-->
                </ul>

                <h4 class="left-history-head mt40">Response Details</h4>
                <ul class="left-history mt10">
                    <!--填充历史信息-->
                </ul>
            </div>
            <div class="right col-sm-10">
                <!--模板填充-->
                <div class="right-info">
                    <div class="line">
                        <select class="form-input col-sm-10" name="" id="markType">
                            <option value="1">订单问题备注</option>
                            <!--<option value="2">退款备注</option>
                            <option value="3">退货备注</option>-->
                        </select>
                        <button id="orderErp" class="btn-e" disabled="disabled">同步ERP</button>
                    </div>
                    <div class="line">
                        <h3>Network station</h3>
                        <p data-name="station"></p>
                    </div>
                    <div class="line">
                        <h3>Customer Contact</h3>
                        <p data-name="buyer"></p>
                    </div>
                    <div class="line">
                        <h3>Shipping Address</h3>
                        <p data-name="shippingAddress"></p>
                    </div>
                    <!--<div class="line">
                        <h3>Shipping</h3>
                        <p data-name="shipping"></p>
                    </div>
                    <div class="line">
                        <h3>Information</h3>
                        <p data-name="information"></p>
                    </div>-->
                    <div class="line">
                        <h3>Transaction ID:</h3>
                        <p data-name="transactionId"></p>
                    </div>
                    <div class="line">
                        <h3>Invoice ID:</h3>
                        <p data-name="orderSn"></p>
                    </div>
                </div>
                <!--单号信息-->
                <div class="right-order">
                    <h3>Return tracking number</h3>
                    <ul class="order-render-box">
                        <!--list-->
                    </ul>
                </div>
                <!--erp信息-->
                <div class="right-erp">
                    <div class="row">
                        <div class="col-sm-12"><h4>Logistics Information:</h4></div>
                        <div class="col-sm-12"><button id="stopOrder" class="btn-b hide">终止订单</button></div>
                    </div>
                    <div class="erp-box">

                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!--渲染模板开始-->

<!-- ai推荐回复模板-->
<script type="text/html" id="resolution-ai-reply-temp">
    <li data-val="MERCHANDISE_OR_SERVICE_NOT_RECEIVED" class="sel-list">Item not received</li>
    <li data-val="MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED" class="sel-list">Item significantly not as described</li>
    <!-- <li data-val="UNAUTHORISED" class="sel-list">Unauthorized transaction</li> -->
    <!-- <li data-val="CREDIT_NOT_PROCESSED" class="sel-list">Missing refund or credit</li> -->
    <!-- <li data-val="DUPLICATE_TRANSACTION" class="sel-list">Duplicate payment</li> -->
    <!-- <li data-val="INCORRECT_AMOUNT" class="sel-list">Wrong amount or date</li> -->
    <!-- <li data-val="PAYMENT_BY_OTHER_MEANS" class="sel-list">Paid with other method</li> -->
    <!-- <li data-val="CANCELED_RECURRING_BILLING" class="sel-list">Cancelled preapproved payment</li> -->
    <!-- <li data-val="OTHER" class="sel-list">Other</li> -->
    <li data-val="CUSTOMER_SAID_ITEM_RETURNED" class="sel-list">Customer_said_item_returned</li>
    <li data-val="ASK_WHICH_SKU_WANT_RETURN" class="sel-list">Ask_which_sku_want_return</li>
    <!-- {{each intentList as v i}}
    <li data-val="{{v.intentKey}}" class="sel-list">
    {{if(v.intentKey.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_RECEIVED')}}item not received{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED')}}item significantly not as described{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='UNAUTHORISED')}}Unauthorized transaction{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='CREDIT_NOT_PROCESSED')}}missing refund or credit{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='DUPLICATE_TRANSACTION')}}Duplicate payment{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='INCORRECT_AMOUNT')}}Wrong amount or date{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='PAYMENT_BY_OTHER_MEANS')}}Paid with other method{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='CANCELED_RECURRING_BILLING')}}Cancelled preapproved payment{{/if}}
    {{if(v.intentKey.toLocaleUpperCase()=='OTHER')}}Other{{/if}}
    </li>
    {{/each}} -->
</script>
<!--erp订单列表模板-->
<script type="text/html" id="resolution-detail-erp">
    <div class="erp-order row mt10">
        <div class="col-sm-12"><label>订单号：</label><span>{{OrderNo}}</span></div>
        <div class="col-sm-12"><label>状态：</label><span>{{ERPStatus}}</span></div>
    </div>
    <ul class="erp-content">
        {{each OrderGoods as v i}}
        {{set isTrue = v.PackageStatus == '已发货' ? true : false}}
        <li class="content-list">
            <div class="text-line">
                {{if(isTrue)}}
                <i class="iconfont icon-yifahuo"></i>
                {{/if}}
                <strong><i class="line-status" style="color:{{isTrue ? '' : '#999'}}">{{v.PackageStatus}}</i></strong>
            </div>
            <div class="text-line row">
                <div class="col-sm-12"><label>sku：</label><span>{{v.SkuId}}</span></div>
                <div class="col-sm-12"><label>描述：</label><span>{{v.Specification}}</span></div>
            </div>
            <div class="text-line row">
                <div class="col-sm-12"><label>跟踪号：</label><span>{{v.ExpressNo}}</span></div>
                <div class="col-sm-12"><label>包裹号：</label><span>{{v.PackageNo}}</span></div>
            </div>
        </li>
        {{/each}}
    </ul>
</script>

<!--重新报价-->
<script id="resolution-detail-layer1" type="text/html">
    <div class="resolution-box">
        <p class="summary">You will be offered replacement items for the buyer without a refund or return the original item.</p>
        <!--<p>买方装运地址：</p>-->
        <p class="summary">Choose a return address</p>
        <section data-name="layer-street-c" class="com-select">
            <div class="sel-item">
                <input class="sel-head" type="text" value="" readonly placeholder="请选择"/>
                <input name="layer-street-c" type="hidden" value="">
                <i class="sel-icon"></i>
            </div>
            <ul class="sel-content">
                <li data-val="A" class="sel-list">5th Floor,Block A, XiaMao Commercial Plaza, Baiyun District, Guangzhou, GUANGDONG 510410</li>
            </ul>
        </section>
        <p class="summary"><span class="layer-name"></span> accepts your offer, you can send replacement items. This event will end when the buyer confirms that the item has been delivered.</p>
        <div class="box-area">
            <textarea id="send-text-a" class="area" placeholder="Enter your offer details"></textarea>
        </div>
    </div>
</script>

<!--退款关闭-->
<script id="resolution-detail-layer2" type="text/html">
    <div class="resolution-box">
        <p class="summary"><span class="layer-name"></span> has requested a refund of <span class="layer-price">00.0EUR</span></p>
        <p class="summary">You will be refunded <span class="layer-price">00.0EUR</span> Buyers do not need to return items. This event will end when you issue a refund to the buyer.</p>
        <div class="box-area">
            <textarea id="send-text-b" class="area" placeholder="Enter your offer details"></textarea>
        </div>
    </div>
</script>

<!--全额退款及退货-->
<script id="resolution-detail-layer3" type="text/html">
    <div class="resolution-box">
        <p class="summary">Refund amount - <span class="layer-price"></span></p>
        <p class="summary">Choose a return address</p>
        <section data-name="layer-street-a" class="com-select">
            <div class="sel-item">
                <input class="sel-head" type="text" value="" readonly placeholder="请选择"/>
                <input name="layer-street-a" type="hidden" value="">
                <i class="sel-icon"></i>
            </div>
            <ul class="sel-content">
                <li data-val="A" class="sel-list">5th Floor,Block A, XiaMao Commercial Plaza, Baiyun District, Guangzhou, GUANGDONG 510410</li>
            </ul>
        </section>
        <p class="summary">Once you confirm receipt of the item returned by the buyer, the refund will be processed immediately.</p>
        <div class="box-area">
            <textarea id="send-text-c" class="area" placeholder="Enter your offer details"></textarea>
        </div>
    </div>
</script>

<!--部分退款优惠-->
<script id="resolution-detail-layer4" type="text/html">
    <div class="resolution-box feat-grid">
        <div id="refundRadio" data-name="comRadio" class="row com-radio mt10" style="width: 100%;">
            <div class="col-sm-6">
                <label class="box-add">
                    <input name="radio-1" type="radio" checked="checked" value="aChecked">
                    <i data-name="radioBox" class="radio-box"></i>
                    <span>I'll issue a partial refund.</span>
                </label>
            </div>
            <div class="col-sm-9">
                <label>
                    <input name="radio-1" type="radio" value="bChecked">
                    <i data-name="radioBox" class="radio-box"></i>
                    <span>I'll issue a partial refund. I want the item to be returned.</span>
                </label>
            </div>
            <div class="col-sm-9">
                <label>
                    <input name="radio-1" type="radio" value="cChecked">
                    <i data-name="radioBox" class="radio-box"></i>
                    <span>I'll issue a partial refund and send a replacement.</span>
                </label>
            </div>
        </div>

        <!--a-->
        <div data-name="aChecked" class="index-refund-box">
            <div class="mt15">
                <div class="form-group-a"><input type="number" class="form-input" min="0"></div>
                <span class="layer-price"></span>
            </div>
            <div class="box-area mt10 clearfix">
                <textarea id="send-text-d" class="area" placeholder="Enter your offer details"></textarea>
                <button id="send-d" type="button" class="btn-a fr mt10">
                    <i class="send-animate"><span class="send-main"></span></i>
                    <span class="send-text">Send Offer</span>
                </button>
            </div>
        </div>
        <!--b-->
        <div data-name="bChecked" class="index-refund-box hide">
            <p class="summary">Once you confirm receipt of the item returned by the buyer, the refund will be processed immediately.</p>
            <div class="form-group-a"><input type="number" class="form-input" min="0"></div>
            <span class="layer-price"></span>
            <p class="summary">Choose a return address.</p>
            <section data-name="layer-street-b" class="com-select">
                <div class="sel-item">
                    <input class="sel-head" type="text" value="" readonly placeholder="请选择"/>
                    <input name="layer-street-b" type="hidden" value="">
                    <i class="sel-icon"></i>
                </div>
                <ul class="sel-content">
                    <li data-val="A" class="sel-list">5th Floor,Block A, XiaMao Commercial Plaza, Baiyun District, Guangzhou, GUANGDONG 510410</li>
                </ul>
            </section>
            <div class="box-area mt10 clearfix">
                <textarea id="send-text-e" class="area" placeholder="Enter your offer details"></textarea>
                <button id="send-e" type="button" class="btn-a fr mt10">
                    <i class="send-animate"><span class="send-main"></span></i>
                    <span class="send-text">Send Offer</span>
                </button>
            </div>
        </div>
        <!--c-->
        <div data-name="cChecked" class="index-refund-box hide">
            <p class="summary"><span class="layer-name"></span> accepts this offer, you can send replacement items or parts. The refund will be processed after the buyer confirms receipt of the item.</p>
            <div class="form-group-a"><input type="number" class="form-input" min="0"></div> <span class="layer-price"></span>
            <!--<p class="mt15">买方装运地址：</p>-->
            <p class="summary">Choose a return address.</p>
            <section data-name="layer-street-d" class="com-select">
                <div class="sel-item">
                    <input class="sel-head" type="text" value="" readonly placeholder="请选择"/>
                    <input name="layer-street-d" type="hidden" value="">
                    <i class="sel-icon"></i>
                </div>
                <ul class="sel-content">
                    <li data-val="A" class="sel-list">5th Floor,Block A, XiaMao Commercial Plaza, Baiyun District, Guangzhou, GUANGDONG 510410</li>
                </ul>
            </section>
            <div class="box-area mt10 clearfix">
                <textarea id="send-text-f" class="area" placeholder="Enter your offer details"></textarea>
                <button id="send-f" type="button" class="btn-a fr mt10">
                    <i class="send-animate"><span class="send-main"></span></i>
                    <span class="send-text">Send Offer</span>
                </button>
            </div>
        </div>
    </div>
</script>

<!--内容列表 当 ai_translate_res 数据为空的时候这使用老版本-->
<script type="text/html" id="resolution-detail-list-old">
    {{each messages as v i}}
    <div class="content-list">
        <div class="list-head" title="{{v.posted_by}}"><i class="head-a {{v.posted_by == 'BUYER' ? '' : 'seller'}}">{{v.posted_by}}</i></div>
        <div class="list-text">
            <div class="text-detail">
                {{@v.content}}
            </div>
            <div class="text-footer">{{v.time_posted}}</div>
        </div>
        <div>语种识别区域</div>
    </div>
    {{/each}}
</script>
<!--内容列表 添加了语种识别-->
<script type="text/html" id="resolution-detail-list">
    {{each ai_translate_res as v i}}
    <div class="content-list">
        <div class="list-head" title="{{v.posted_by}}"><i class="head-a {{v.posted_by == 'BUYER' ? '' : 'seller'}}">{{v.posted_by}}</i></div>
        <div class="list-text">
            <div class="text-detail">
                {{@v.content}}
            </div>
            <div class="text-footer">{{v.time_posted}}</div>
            {{if(v.posted_by === 'BUYER')}}
            <div class="text-intent">
                {{if(ai_translate_res.length !== i+1)}}
                {{if(v.intents)}}
                {{if(v.intents.length > 0)}}
                <span>Intent：
                        {{each v.intents as it,ii}}
                        <span>
                            {{if(ii !== 0)}},{{/if}}
                            {{if(it.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_RECEIVED')}}Item not received{{/if}}
                            {{if(it.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED')}}Item significantly not as described{{/if}}
                            {{if(it.toLocaleUpperCase()=='UNAUTHORISED')}}Unauthorized transaction{{/if}}
                            {{if(it.toLocaleUpperCase()=='CREDIT_NOT_PROCESSED')}}Missing refund or credit{{/if}}
                            {{if(it.toLocaleUpperCase()=='DUPLICATE_TRANSACTION')}}Duplicate payment{{/if}}
                            {{if(it.toLocaleUpperCase()=='INCORRECT_AMOUNT')}}Wrong amount or date{{/if}}
                            {{if(it.toLocaleUpperCase()=='PAYMENT_BY_OTHER_MEANS')}}Paid with other method{{/if}}
                            {{if(it.toLocaleUpperCase()=='CANCELED_RECURRING_BILLING')}}Cancelled preapproved payment{{/if}}
                            {{if(it.toLocaleUpperCase()=='OTHER')}}Other{{/if}}
                            {{if(it.toLocaleUpperCase()=='CUSTOMER_SAID_ITEM_RETURNED')}}Customer said item returned{{/if}}
                            {{if(it.toLocaleUpperCase()=='REFUND')}}Refund{{/if}}
                        </span>
                        {{/each}}
                    </span>
                {{/if}}
                {{/if}}
                {{/if}}
                {{if(ai_translate_res.length === i+1)}}
                Intent：
                <span class='intentForView'>
                        {{each v.intents as it,ii}}
                                {{if(ii !== 0)}},{{/if}}
                                {{if(it.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_RECEIVED')}}Item not received<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED')}}Item significantly not as described<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='UNAUTHORISED')}}Unauthorized transaction<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='CREDIT_NOT_PROCESSED')}}Missing refund or credit<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='DUPLICATE_TRANSACTION')}}Duplicate payment<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='INCORRECT_AMOUNT')}}Wrong amount or date<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='PAYMENT_BY_OTHER_MEANS')}}Paid with other method<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='CANCELED_RECURRING_BILLING')}}Cancelled preapproved payment<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='OTHER')}}Other<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='CUSTOMER_SAID_ITEM_RETURNED')}}Customer said item returned<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                                {{if(it.toLocaleUpperCase()=='REFUND')}}Refund<span class="intentDel" data-index="{{ii}}">x</span>{{/if}}
                        {{/each}}
                    </span>
                <select name="intent" id="intent" placeholder="select intent">
                    <option>select intent</option>
                    <option value="MERCHANDISE_OR_SERVICE_NOT_RECEIVED" title="MERCHANDISE_OR_SERVICE_NOT_RECEIVED">Item not received</option>
                    <option value="MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED" title="MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED">Item significantly not as described</option>
                    <option value="UNAUTHORISED" title="UNAUTHORISED">Unauthorized transaction</option>
                    <option value="CREDIT_NOT_PROCESSED" title="CREDIT_NOT_PROCESSED">Missing refund or credit</option>
                    <option value="DUPLICATE_TRANSACTION" title="DUPLICATE_TRANSACTION">Duplicate payment</option>
                    <option value="INCORRECT_AMOUNT" title="INCORRECT_AMOUNT">Wrong amount or date</option>
                    <option value="PAYMENT_BY_OTHER_MEANS" title="PAYMENT_BY_OTHER_MEANS">Paid with other method</option>
                    <option value="CANCELED_RECURRING_BILLING" title="CANCELED_RECURRING_BILLING">Cancelled preapproved payment</option>
                    <option value="CUSTOMER_SAID_ITEM_RETURNED" title="CUSTOMER_SAID_ITEM_RETURNED">Customer said item returned</option>
                    <option value="REFUND" title="REFUND">Refund</option>
                    <option value="OTHER" title="OTHER">Other</option>
                </select>
            </div>
            {{/if}}

            {{if(v.translated)}}
            <div class="text-laguage">Translation：
                <span>Language: {{v.language}}</span>
                <span class="laguage-content">{{@v.translated}}</span>
            </div>
            {{/if}}
            {{/if}}
            {{if(v.posted_by === 'SELLER')}}
            {{if(ai_translate_res.length === i+1)}}
            {{if(v.intents)}}
            {{if(v.intents.length > 0)}}
            <span>Intent：{{v.intents.join(',')}}</span>
            {{/if}}
            {{/if}}
            {{/if}}
            {{/if}}
            {{if(v.order_tag_status)}}
            {{if(v.order_tag_status.length > 0)}}
            <div class="text-intent">Logistics：
                {{each v.order_tag_status as o}}
                <span>{{o}},</span>
                {{/each}}
            </div>
            {{/if}}
            {{/if}}
        </div>
    </div>
    {{/each}}
</script>
<!--历史列表-->
<script type="text/html" id="resolution-detail-history">
    {{if(response_info_log || response_refund_log)}}
    {{each response_refund_log as v i}}
    <li style="list-style-type: disc;list-style-position:inside;">{{v}}</li>
    {{/each}}
    {{each response_info_log as v i}}
    <li style="list-style-type: disc;list-style-position:inside;">{{v}}</li>
    {{/each}}
    {{else}}
    <p>暂无历史数据</p>
    {{/if}}
</script>

<script type="text/html" id="resolution-detail-offer">
    {{if(offer)}}
    {{each offer.history as v i}}
    <div><strong>Time：</strong><span>{{v.offer_time}}</span>&nbsp;&nbsp; <strong>Actor：</strong><span>{{v.actor}}</span>&nbsp;&nbsp; <strong>Event Type：</strong><span>{{v.event_type}}</span></div>
    {{/each}}
    {{else}}
    <p>暂无数据</p>
    {{/if}}
</script>

<!--模板列表-->
<script type="text/html" id="resolution-tmp-send">
    {{each request_ai_list as v i}}
    <label class="mr10">
        <input name="radio-1" type="radio" value="{{v.content}}">
        <i data-name="radioBox" class="radio-box"></i>
        <span>模版{{i + 1}}</span>
    </label>
    {{/each}}
    <!-- <label class="mr10">
         <input name="radio-1" type="radio" value="bChecked">
         <i data-name="radioBox" class="radio-box"></i>
         <span>模版2</span>
     </label>-->
</script>
<!--原因类型1-->
<script type="text/html" id="resolution-tmp-orderErp">
    <section class="layer-box-erp">
        <form id="form-erp" class="box-content">
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">商品sku：</label></div>
                <div class="col-sm-12 form-content">
                    <section id="skuID" data-name="com-check" class="com-check">
                        <label data-name="checkAll">
                            <i data-name="allStyle" class="check-box"></i>
                            <span>全选</span>
                        </label>
                        <div data-name="orderSkuList">

                        </div>
                    </section>
                </div>
            </div>
            <!--<div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">问题类型：</label></div>
                <div class="col-sm-12 form-content">
                    <section data-name="ProblemType" class="com-select">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="reason type"/>
                            <input name="ProblemType" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <ul data-name="reasonTypeList" class="sel-content">
                        </ul>
                    </section>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">投诉渠道：</label></div>
                <div class="col-sm-12 form-content">
                    <section data-name="ComplaintChannel" class="com-select">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="e-mail address"/>
                            <input name="ComplaintChannel" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <ul data-name="channelList" class="sel-content"></ul>
                    </section>
                </div>
            </div>-->
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">争议阶段：</label></div>
                <div class="col-sm-12 form-content">
                    <section data-name="ControversyStage" class="com-select">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="e-mail address"/>
                            <input name="ControversyStage" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <ul data-name="ControversyStageList" class="sel-content"></ul>
                    </section>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">问题分类：</label></div>
                <div class="col-sm-12 form-content">
                    <section data-name="reason" class="com-select-floor" style="z-index:9;">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="please select"/>
                            <input name="reason" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <div class="sel-box"></div>
                    </section>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5">备注：</label></div>
                <div class="col-sm-12 form-content">
                    <div class="sel-item">
                        <textarea class="" name="Remark" id=""></textarea>
                    </div>
                </div>
            </div>
        </form>
    </section>
</script>
<!--原因类型2-->
<script type="text/html" id="resolution-tmp-orderErp2">
    <section class="layer-box-erp">
        <form id="form-erp2" class="box-content">
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">商品sku：</label></div>
                <div class="col-sm-12 form-content">
                    <section data-name="skuID" class="com-select">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="sku"/>
                            <input name="skuID" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <ul data-name="orderSkuList" class="sel-content">
                        </ul>
                    </section>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">退款金额：</label></div>
                <div class="col-sm-12">
                    <div class="sel-item"><input name="refund" type="text" class="form-input"></div>
                </div>
            </div>
        </form>
    </section>
</script>
<!--原因类型3-->
<script type="text/html" id="resolution-tmp-orderErp3">
    <section class="layer-box-erp">
        <form id="form-erp3" class="box-content">
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">物流公司：</label></div>
                <div class="col-sm-12"><input name="logistics" type="text" class="form-input"></div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">运单号：</label></div>
                <div class="col-sm-12"><input name="orderNumber" type="text" class="form-input"></div>
            </div>
        </form>
    </section>
</script>

<!--物流订单列表-->
<script id="resolution-detail-tracking-list" type="text/html">
    {{each buyer_return_tracking_info as v i}}
        <li><label>{{v.carrier_name}}</label>&nbsp;-&nbsp;<span>{{v.tracking_number}}</span></li>
    {{/each}}
</script>

<script type="text/javascript" src="/src/lib/jquery.validate.min.js"></script>
<script type="text/javascript" src="/src/js/resolution/markType.js"></script>
<!-- js -->
<script>
    let _selectedIntentContent = '' // 被选中的模板初始内容
    $.extend(window.p,{
        src : [],
        //邮件必选
        isCheck:null,
        //发送信息邮件按钮
        emailObj:null,
        //保存当前case信息
        sendInfo:{},
        //send-info
        quill:null,
        //模板选择
        tmpRadio:null,
        layerOrderErp:null,
        //订单数据
        orderArr:[],
        //sku列表
        skuID:[],
        //option数据
        optionObj:{},
        //提交备注数据
        markData1:{},
        markData2:{},
        markData3:{},
        markData4:{}
    });

    $(function(){

        init();

        function init(){

            //初始化选择组件
            p.isCheck = $("#isCheck").comCheck();
            //初始请求
            p.urlPara && requestDetail(p.urlPara);
            //返回
            $(".back").click(function(){
                window.history.go(-1);
            });
            //清除多余邮件cookie
            clearEmail();

            //更新
            $("#update").on('click',function(){
                requestDetail(p.urlPara,'update_dispute')
            })

            // 重新翻译
            $('#translation').on('click', function(){
                retranslation()
            })

            //终止订单
            $("#stopOrder").on('click',function(){
                var order = p.sendInfo.order_sn;
                var id = p.sendInfo.erp_site_id;
                app.ajax({
                    type:'post',
                    //url:"https://api-erp.orderplus.com/api/order/termination_order?orderNo=O142688&siteId=17&remark=测试",
                    url:"https://api-erp.orderplus.com/api/order/termination_order?orderNo="+order+"&siteId=" + id + "&remark=客人要求终止",
                    success:function(res){
                        if((res.code == 200) && (res.status == 1)){
                            $.comMessage({
                                type:'warning',
                                text:'订单终止成功！',
                                time:6000
                            });
                            $("#stopOrder").addClass('hide');
                        }else{
                            $.comMessage({
                                type:'warning',
                                text:res.message
                            });
                        }
                    }
                })
            });

            //重新报价
            $("#quote").on('click',function(){
                var dom = $("#resolution-detail-layer1");
                var self = new ComLayer({
                    dom:dom.html(),
                    title:'Replacement item offer',
                    okText:'Send Offer',
                    okHandler:function(buttonObj){
                        var val = $("#send-text-a").val();
                        if(val.length){
                            RequestRefunds({
                                type:'REPLACEMENT_WITHOUT_REFUND',
                                note:val,
                                isPrice:false,
                                self:self,
                                address:$("input[name='layer-street-c']").val(),
                                btnObj:buttonObj
                            })
                        }else{
                            $.comMessage({
                                type:'prompt',
                                text:'请填写备注内容！',
                            })
                        }
                    },
                    callback:function(){
                        $(".layer-name").html(p.sendInfo.details.buyer);
                        $("[data-name='layer-street-c']").comSelect({init:true});
                    }
                })

            });

            //退款关闭
            $("#refund").on('click',function(){
                var dom = $("#resolution-detail-layer2");
                var self = new ComLayer({
                    dom:dom.html(),
                    title:'Full Refund',
                    okText:'Refund and Close',
                    okHandler:function(buttonObj){
                        var val = $("#send-text-b").val();
                        refund({
                            type:'',
                            isPrice:true,
                            note:val,
                            self:self,
                            btnObj:buttonObj
                        });
                    },
                    callback:function(){
                        $(".layer-name").html(p.sendInfo.details.buyer);
                        $(".layer-price").html(p.sendInfo.dispute_amount_value + p.sendInfo.dispute_amount_currency_code);
                    }
                })
            })
            //全额退款及退货
            $("#refund-all").on('click',function(){
                var dom = $("#resolution-detail-layer3");
                var self = new ComLayer({
                    dom:dom.html(),
                    title:'full refund offer with item return',
                    okText:'Refund and Close',
                    okHandler:function(buttonObj){
                        var val = $("#send-text-c").val();
                        if(val.length){
                            RequestRefunds({
                                type:'REFUND_WITH_RETURN',
                                note:val,
                                isPrice:true,
                                self:self,
                                address:$("input[name='layer-street-a']").val(),
                                btnObj:buttonObj
                            })
                        }else{
                            $.comMessage({
                                type:'prompt',
                                text:'请填写备注内容！',
                            })
                        }
                    },
                    callback:function(){
                        $(".layer-price").html(p.sendInfo.dispute_amount_value + p.sendInfo.dispute_amount_currency_code);
                        $("[data-name='layer-street-a']").comSelect({init:true});
                    }
                })
            })

            //部分退款和关闭
            $("#part").on('click',function(){
                var dom = $("#resolution-detail-layer4");
                var self = new ComLayer({
                    dom:dom.html(),
                    title:'Partial refund offer',
                    displayFooter:true,
                    callback:function(){
                        //切换事件
                        var obj = $('#refundRadio').comRadio();
                        $(".resolution-box").on('change',"input[name='radio-1']",function(){
                            var self = $("[data-name='"+obj.checked()+"']");
                            self.removeClass('hide');
                            $('.index-refund-box').not(self).addClass('hide');
                        })

                        $(".layer-name").html(p.sendInfo.details.buyer);
                        $(".layer-price").html(p.sendInfo.dispute_amount_currency_code);
                        $("[data-name='layer-street-b']").comSelect({init:true});
                        $("[data-name='layer-street-d']").comSelect({init:true});
                        //各级别事件
                        //child-d
                        $("#send-d").click(function(){
                            var val = $("#send-text-d").val();
                            var number = $(this).closest('.index-refund-box').find("input[type='number']").val();
                            if(val.length && number){
                                RequestRefunds({
                                    type:'REFUND',
                                    note:val,
                                    isPrice:true,
                                    self:self,
                                    price:number,
                                    btnObj:$(this)
                                })
                            }else{
                                $.comMessage({
                                    type:'prompt',
                                    text:'备注内容或金额不能为空！',
                                })
                            }
                        })
                        //child-e
                        $("#send-e").click(function(){
                            var val = $("#send-text-e").val();
                            var number = $(this).closest('.index-refund-box').find("input[type='number']").val();
                            if(val.length && number){
                                RequestRefunds({
                                    type:'REFUND_WITH_RETURN',
                                    note:val,
                                    self:self,
                                    isPrice:true,
                                    price:number,
                                    address:$("input[name='layer-street-b']").val(),
                                    btnObj:$(this)
                                })
                            }else{
                                $.comMessage({
                                    type:'prompt',
                                    text:'备注内容或金额不能为空！',
                                })
                            }
                        })
                        //child-f
                        $("#send-f").click(function(){
                            var val = $("#send-text-f").val();
                            var number = $(this).closest('.index-refund-box').find("input[type='number']").val();
                            if(val.length){
                                RequestRefunds({
                                    type:'REFUND_WITH_REPLACEMENT',
                                    note:val,
                                    self:self,
                                    isPrice:true,
                                    price:number,
                                    address:$("input[name='layer-street-d']").val(),
                                    btnObj:$(this)
                                })
                            }else{
                                $.comMessage({
                                    type:'prompt',
                                    text:'备注内容或金额不能为空！',
                                })
                            }
                        })
                    }
                })
            });

            p.emailObj = $("[data-name='sendInfoEmail']").comSelect({
                search:true,
            });

            $("#emailInput").on({
                focus:function(){
                    var list = com.getCookie('emailList') ? JSON.parse(com.getCookie('emailList')) : null;
                    if(list && list.length){
                        p.emailObj.render(list);
                    }
                },
                input:function(){
                    $("[name='sendInfoEmail']").val(this.value);
                }
            })

            $("#sendInfo").on('click',function(e){
                e.stopPropagation();
                var that = $(this);
                var content = $("#sendInfoMsg").val();
                if(content.length>2000){
                    $.comMessage({
                        type:'prompt',
                        text:'文字数量需小于2000！',
                    })
                    return;
                }
                if(content.length<1){
                    $.comMessage({
                        type:'prompt',
                        text:'请填写回复内容！',
                    })
                }else{
                    app.ajax({
                        type:'post',
                        url:app.api('/api/sendMsgToBuyer'),
                        data:{
                            msg:content,
                            email_cs_admin_id:para.user.email_cs_admin_id,
                            site_id:p.sendInfo.site_id,
                            dispute_id:p.sendInfo.dispute_id,
                            dispute_life_cycle_stage:p.sendInfo.dispute_life_cycle_stage,
                            current_status:p.sendInfo.status,
                            dispute_amount:p.sendInfo.dispute_amount,
                            email:$("[name='sendInfoEmail']").val(),
                            is_use: _selectedIntentContent.length > 0 ? 1:0,
                            // is_use: 1,
                            intention_content:_selectedIntentContent
                        },
                        beforeSend:function(){
                            that.addClass('active-animate');
                            that.prop("disabled",true);
                        },
                        success:function(res){
                            if(res.code == 0){
                                trackEmailSave();
                                $.comMessage({
                                    type:'prompt',
                                    text:res.msg,
                                    time:8000,
                                    callback:function(){
                                        requestDetail(p.urlPara);
                                        $("#sendInfoMsg").val("")
                                    }
                                });
                            }else{
                                $.comMessage({
                                    type:'prompt',
                                    text:res.msg,
                                })
                            }
                        },
                        complete:function(){
                            that.removeClass('active-animate');
                            that.prop("disabled",false);
                        }
                    });
                }
            });

            //模板选择
            $("#resolutionTmpSend").on('change','input',function(){
                //console.log()
                $("#sendInfoMsg").val(p.tmpRadio.checked())
            })
            //清除模板选择内容
            $("#clearTmp").on('click',function(){
                var labelObj = $("#resolutionTmpSend");
                labelObj.find('label').removeClass('box-add');
                labelObj.find('label').find('input').prop('checked',false);
                $("#sendInfoMsg").val('');
            })


            //订单同步
            reqOption();

            $("#orderErp").on('click',function(){
                var val = $("#markType").val();
                switch(val){
                    case '1':markType1();break;
                    case '2':markType2();break;
                    case '3':markType3();break;
                }
            })

            //此事件为当前comSelect组件下拉列表点击时触发校验
            $("body").on('click','.sel-list',function(){
                $("#form-erp").valid();
                $("#form-erp2").valid();
            });
        }


        //详情
        function requestDetail(val,update){
            var loadObj = null;
            app.ajax({
                type:'get',
                url:app.api("/api/getDispute/" + val + '/'+ (update || '')),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".left-content"),
                    });
                },
                success:function(res){
                    if(res.code == 0){
                        $(".time").html(res.data.create_date);
                        $(".money").html(res.data.dispute_amount_currency_code + res.data.dispute_amount_value);
                        $(".money-tran").html(res.data.transcation_amount_currency_code + res.data.transcation_account_value);

                        $("[data-name='reason']").html(res.data.current_reason);
                        $("[data-name='disputeId']").html(res.data.dispute_id);
                        $("[data-name='transactionId']").html(res.data.details.transaction_id);
                        $("[data-name='orderSn']").html(res.data.order_sn);
                        $("[data-name='station']").html(res.data.order_sn_site_name);
                        var domList = ''
                        if(res.data.ai_translate_res.length === 0){
                            domList = template('resolution-detail-list-old',res.data);
                        }else{
                            if(typeof res.data.ai_translate_res[res.data.ai_translate_res.length-1].intents === 'string' &&
                                res.data.ai_translate_res[res.data.ai_translate_res.length-1].intents.length > 0){
                                res.data.ai_translate_res[res.data.ai_translate_res.length-1].intents=[res.data.ai_translate_res[res.data.ai_translate_res.length-1].intents]
                            }
                            domList = template('resolution-detail-list',res.data);
                        }
                        $(".left-content").html(domList);
                        //历史对话记录
                        var historyDom = template('resolution-detail-history',res.data);
                        $(".left-history").html(historyDom);
                        //offer记录
                        var offerDom = template('resolution-detail-offer',res.data);
                        $('.left-offer').html(offerDom);
                        //物流追踪列表
                        var trackDom = template('resolution-detail-tracking-list',res.data);
                        $('.order-render-box').html(trackDom);

                        //渲染模板标签
                        // sendTmp(res.data);

                        //保存数据
                        p.sendInfo = res.data;
                        //请求ERP
                        if(!update){
                            requestErp();
                        }
                        //状态隐藏
                        isHiddenView();
                        $('.intentDel').click(function(){
                            let _index = $(this).attr('data-index')
                            let _buyers = p.sendInfo.ai_translate_res.filter(item => item.posted_by === 'BUYER')
                            let _intent = _buyers[_buyers.length -1].intents
                            _intent.splice(_index, 1)
                            putIntent({ intent: _intent })
                            // $.alert({
                            //     message:'提示',
                            //     detail:'确定删除此意图',
                            //     singleButton:true,
                            //     okHandler:function(){
                            //         let _index = $(this).attr('data-index')
                            //         let _buyers = p.sendInfo.ai_translate_res.filter(item => item.posted_by === 'BUYER')
                            //         let _intent = _buyers[_buyers.length -1].intents
                            //         _intent.splice(_index, 1)
                            //         putIntent({ intent: _intent })
                            //     },
                            //     cancelHandler:function(){
                            //     }
                            // })
                        })
                        $('#intent').change(() =>{
                            let _buyers = p.sendInfo.ai_translate_res.filter(item => item.posted_by === 'BUYER')
                            let _intent = _buyers[_buyers.length -1].intents
                            let _newVal = $('#intent').val()
                            if(_newVal == "select intent"){
                                return
                            }
                            // let _newText = $('#intent').find("option:selected").text()
                            if(_intent.includes(_newVal)){
                                $.comMessage({
                                    type:'prompt',
                                    text:'意图不可重复添加'
                                })
                                return
                            }
                            _intent.push(_newVal)
                            putIntent({intent: _intent})
                        })
                        getDefaultTmp()
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            });
        }

        function putIntent(pram){
            var loadObj = null;
            app.ajax({
                type:'post',
                // traditional:true,
                url:app.api('/api/updateDisputeUserInetens'),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".left-content"),
                    });
                },
                data: { dispute_id: p.sendInfo.dispute_id, ai_translate_res_last: pram.intent.join(',') },
                success:function(res){
                    if(res.code == 0){
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                            time:3000,
                            callback:function(){
                                // history.go(-1)
                            }
                        });
                    }else{
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                        })
                    }
                },
                complete:function(){
                    let _intentHtml = []
                    pram.intent.forEach((int,index) => {
                        let _intentText = null
                        if(int.toLocaleUpperCase() == 'MERCHANDISE_OR_SERVICE_NOT_RECEIVED') _intentText = 'Item not received'
                        if(int.toLocaleUpperCase() == 'MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED') _intentText = 'Item significantly not as described'
                        if(int.toLocaleUpperCase() == 'UNAUTHORISED') _intentText = 'Unauthorized transaction'
                        if(int.toLocaleUpperCase() == 'CREDIT_NOT_PROCESSED') _intentText = 'Missing refund or credit'
                        if(int.toLocaleUpperCase() == 'DUPLICATE_TRANSACTION') _intentText = 'Duplicate payment'
                        if(int.toLocaleUpperCase() == 'INCORRECT_AMOUNT') _intentText = 'Wrong amount or date'
                        if(int.toLocaleUpperCase() == 'PAYMENT_BY_OTHER_MEANS') _intentText = 'Paid with other method'
                        if(int.toLocaleUpperCase() == 'CANCELED_RECURRING_BILLING') _intentText = 'Cancelled preapproved payment'
                        if(int.toLocaleUpperCase() == 'CUSTOMER_SAID_ITEM_RETURNED') _intentText = 'Customer said item returned'
                        if(int.toLocaleUpperCase() == 'REFUND') _intentText = 'Refund'
                        if(int.toLocaleUpperCase() == 'OTHER') _intentText = 'Other'
                        _intentHtml.push(`<span>${_intentText}</span><span class="intentDel" data-index="${index}"
                        style=" color: red; cursor: pointer;display:inline-block;">x</span>\t`)
                    })
                    $('.intentForView').html(_intentHtml)
                    $('.intentDel').click(function(){
                        let _index = $(this).attr('data-index')
                        pram.intent.splice(_index, 1)
                        putIntent({ intent: pram.intent })
                        // $.alert({
                        //         message:'提示',
                        //         detail:'确定删除此意图',
                        //         singleButton:true,
                        //         okHandler:function(){
                        //             let _index = $(this).attr('data-index')
                        //             pram.intent.splice(_index, 1)
                        //             putIntent({ intent: pram.intent })
                        //         },
                        //         cancelHandler:function(){
                        //         }
                        //     })
                    })
                    loadObj.close()
                }
            });
        }

        // 重新翻译
        function retranslation(){
            var loadObj = null;
            app.ajax({
                type:'get',
                url:app.api(`/api/retranslate/${$('[data-name="disputeId"]').html()}`),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".left-content"),
                    });
                },
                success:function(res){
                    if(res.code == 0){
                        window.location.reload()
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.message
                        });
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            })
        }
        //保存默认发送成功的邮箱
        function trackEmailSave(){
            var text = $("#emailInput").val();
            if(!text){return}
            var list = com.getCookie('emailList') ? JSON.parse(com.getCookie('emailList')) : null;
            var isTrue = false;
            if(list){
                $.each(list,function(index,item){
                    if(item.value == text){
                        isTrue = true;
                        return false;
                    }
                });
                if(!isTrue){
                    list.unshift({name:text,value:text});
                    com.setCookie('emailList',JSON.stringify(list))
                }
            }else{
                com.setCookie('emailList',JSON.stringify([{name:text,value:text}]))
            }
        }

        //清除默认发送成功的邮箱
        function clearEmail(){
            var data = com.getCookie('emailList') ? JSON.parse(com.getCookie('emailList')) : null;
            if( data && data.length>=20){
                data.splice(-5,5);
                com.setCookie('emailList',JSON.stringify(data))
            }
        }

        //议价退款接口调用
        function RequestRefunds(op){
            var code = "";
            var price = "";
            if(op.isPrice){
                code = p.sendInfo.dispute_amount_currency_code;
                price = op.price ? op.price : p.sendInfo.dispute_amount_value;
            }
            app.ajax({
                type:'post',
                url:app.api('/api/bargain'),
                beforeSend:function(){
                    op.btnObj.addClass('active-animate');
                    op.btnObj.prop("disabled",true);
                },
                data:{
                    email_cs_admin_id:para.user.email_cs_admin_id,
                    site_id:p.sendInfo.site_id,
                    dispute_id:p.sendInfo.dispute_id,
                    dispute_life_cycle_stage:p.sendInfo.dispute_life_cycle_stage,
                    current_status:p.sendInfo.status,
                    note : op.note,
                    offer_type : op.type,
                    order_sn:p.sendInfo.order_sn,
                    shipping_address : op.address,
                    offer_amount:{
                        currency_code:code,
                        value:price
                    }
                },
                success:function(res){
                    if(res.code == 0){
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                            time:3000,
                            callback:function(){
                                history.go(-1)
                            }
                        });
                    }else{
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                        })
                    }
                },
                complete:function(){
                    op.self.close();
                    op.btnObj.removeClass('active-animate');
                    op.btnObj.prop("disabled",false);
                }
            });
        }
        //退款接口调用
        function refund(op){
            app.ajax({
                type:'post',
                url:app.api('/api/acceptClaim'),
                beforeSend:function(){
                    op.btnObj.addClass('active-animate');
                    op.btnObj.prop("disabled",true);
                },
                data:{
                    email_cs_admin_id:para.user.email_cs_admin_id,
                    site_id:p.sendInfo.site_id,
                    dispute_id:p.sendInfo.dispute_id,
                    dispute_life_cycle_stage:p.sendInfo.dispute_life_cycle_stage,
                    current_status:p.sendInfo.status,
                    note : op.note,
                    is_full_refund:1,
                    reason:p.sendInfo.reason,
                    order_sn:p.sendInfo.order_sn,
                },
                success:function(res){
                    if(res.code == 0){
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                            time:3000,
                            callback:function(){
                                history.go(-1)
                            }
                        });
                    }else{
                        $.comMessage({
                            type:'prompt',
                            text:res.msg,
                        })
                    }
                },
                timeout:40000,
                complete:function(){
                    op.self.close();
                    op.btnObj.removeClass('active-animate');
                    op.btnObj.prop("disabled",false);
                }
            });
        }

        //erp请求
        function requestErp(){
            var order = encodeURIComponent(p.sendInfo.order_sn);
            var id = p.sendInfo.erp_site_id;
            let _url = "https://api-erp.orderplus.com/api/logistics/GetOrderPackage?orderNo="+order+"&siteId=" + id + "&transaction_id=" + p.sendInfo.details.transaction_id
            $.post(_url, {},function (res) {
                if(res.code == 200){
                    var dom = template('resolution-detail-erp',res.response);
                    $(".erp-box").html(dom);
                    //右侧信息填充
                    renderRightInfo(res.response);
                    p.orderArr = res.response.OrderGoods;
                }else{
                    $.comMessage({
                        type:'warning',
                        text:res.error
                    });
                }
            })
        }

        function renderRightInfo(erp){
            if(!erp){
                $(".erp-box").html("<p class='mt10'>Temporarily no data please manually query！</p>");
                return;
            }
            if(erp.ERPStatus == '已付款' || erp.ERPStatus== '待审核'){
                $("#stopOrder").removeClass('hide');
            }
            var str2 = erp && (erp.Consignee + "<br/>");
            var str3 = erp && (erp.Email + "<br/>");
            $("[data-name='buyer']").html(str2 + str3);
            $("[data-name='shippingAddress']").html(erp && erp.Address);
            $(".pay").html(erp && erp.Consignee);
            p.sendInfo.order_sn = (erp && erp.OrderNo);
        }

        //隐藏是否
        function isHiddenView(){
            if(p.sendInfo.reason != 'MERCHANDISE_OR_SERVICE_NOT_RECEIVED'){
                $("#quote").removeClass('hide');
                $("#part").removeClass('hide');
                $("#refund-all").removeClass('hide');
            }
            if(p.sendInfo.status == "RESOLVED" || p.sendInfo.status == 'UNDER_REVIEW'){
                $(".left-message").addClass('hide');
            }
        }

        //模板请求
        /*var d = {
            request_ai_list:[
                {
                    "content": "[[SV39259]]\r\nDear customer,\r\n\r\nI have checked your order it has been sent out with the tracking NO. [[RN436680650CN ]].\r\nYou can check the tracking details by visiting the following link:\r\n[XXXXXXXXXX]\r\nThe following is the latest tracking information:\r\n[XXXXXXXXXX]\r\n\r\nAnd the tracking information shows that your parcel has been delivered. Have you received it?\r\n\r\nPlease confirm that the delivery address is correct:\r\n\r\n\r\n[[Receiver      Alexandre Facchini\r\nAddress         Estrada Carlos Queiroz Telles  101  111-b Jardim Fonte do Morumbi\r\nDistrict        Empty\r\nCity             São Paulo\r\nState           São Paulo\r\nState Code   state_code_value\r\nCountry      BR\r\nZip Code     05704-150\r\nPhone Number     5511999511550]]\r\n\r\nIf you have any other problems, please let me know and will try my best to figure out for you."
                },
                {content:456}
            ]
        }
        sendTmp(d)*/
        function sendTmp(data){
            // var dom = template('resolution-tmp-send',data);
            // p.tmpRadio = $("#resolutionTmpSend").html(dom).comRadio();
            let _list = []
            // let listTmp = template('resolution-ai-reply-temp', {intentList:_list});
            let listTmp = template('resolution-ai-reply-temp');
            $("#aiReplyTemp").html(listTmp);
            $("[data-name='aiReplyTemp']").comSelect({
                init:true,
                callback:function(val,text){
                    getTmpByIntent(val)
                }
            });
            if(!data){
                return
            }
            if(!data.hasOwnProperty('ai_reply_tmp')){
                return
            }
            if(!data.ai_reply_tmp.hasOwnProperty('list')){
                return
            }

            Object.keys(data.ai_reply_tmp.list).forEach(intent => {
                _list.push({...data.ai_reply_tmp.list[intent],intentKey:intent.toLocaleUpperCase()})
            })

            // 默认模板为返回数据第一个
            if(_list.length > 0){
                $('#sendInfoMsg').val(`${_list[0].contentResponse}`)
                _selectedIntentContent = _list[0].contentResponse
            }
        }

        // 获取默认推荐模板
        function getDefaultTmp(){
            // var loadObj = null;
            app.ajax({
                type:'get',
                url:app.api(`/api/getDefaultAiTmp/${p.sendInfo.dispute_id}`),
                beforeSend:function(){
                    // loadObj = $.load({
                    //     insert:$("#resolution-detail"),
                    // });
                },
                success:function(res){
                    if(res.code == 0){
                        if(res.data.list){
                            let _keys = Object.keys(res.data.list)
                            let _tempSend={content:'', intent:''}
                            for(let i=0; i< _keys.length; i++){
                                if(_keys[i].toLocaleUpperCase() === 'MERCHANDISE_OR_SERVICE_NOT_RECEIVED'){
                                    _tempSend.content = res.data.list[_keys[i]].contentResponse
                                    _tempSend.intent = _keys[i]
                                    break
                                }
                                if(_keys[i].toLocaleUpperCase() === 'MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED'){
                                    _tempSend.content = res.data.list[_keys[i]].contentResponse
                                    _tempSend.intent = _keys[i]
                                    break
                                }
                                if(_keys[i].toLocaleUpperCase() === 'CUSTOMER_SAID_ITEM_RETURNED'){
                                    _tempSend.content = res.data.list[_keys[i]].contentResponse
                                    _tempSend.intent = _keys[i]
                                    break
                                }
                                if(_keys[i].toLocaleUpperCase() === 'ASK_WHICH_SKU_WANT_RETURN'){
                                    _tempSend.content = res.data.list[_keys[i]].contentResponse
                                    _tempSend.intent = _keys[i]
                                    break
                                }
                            }
                            if($('#sendInfoMsg').val().length===0){
                                $('#sendInfoMsg').val(_tempSend.content)
                                $('#selectedIntent').val(getIntentNameByIntentKey(_tempSend.intent))
                                _selectedIntentContent = _tempSend.content
                            }
                            sendTmp(res.data)
                            // refund = true 设置全额退款按钮背景色
                            if(res.data.refund){
                                $("#refund").addClass('btn-orange')   
                            }
                             // 获取默认模板后如果对话列表中最后一条卖家有意图标识则需要根据对应意图加载模板数据
                            let _buyers = p.sendInfo.ai_translate_res.filter(item => item.posted_by === 'BUYER')
                            if(_buyers[_buyers.length-1].intents){
                                if(_buyers[_buyers.length-1].intents.length >= 1){
                                    getTmpByIntent(_buyers[_buyers.length-1].intents[0])
                                    sendTmp()
                                    return
                                }
                            }
                        } else {
                            $('#sendInfoMsg').val('')
                        }
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.message
                        });
                    }
                },
                complete:function(){
                    // loadObj.close()
                }
            })
        }

        // 获取意图对应的模板
        function getTmpByIntent(intent){
            if(!intent){
                return
            }
            var loadObj = null;
            app.ajax({
                type:'get',
                url:app.api(`/api/getSingleAiTmp/${p.sendInfo.dispute_id}/${intent}`),
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$("#resolution-detail"),
                    });
                },
                success:function(res){
                    if(res.code == 0){
                        if(res.data.list){
                            if(res.data.list.length > 0){
                                $('#sendInfoMsg').val(res.data.list[0].contentResponse+'')
                                $('#selectedIntent').val(getIntentNameByIntentKey(intent))
                                _selectedIntentContent = res.data.list[0].contentResponse
                            }
                            else{
                                _selectedIntentContent=''
                                $('#sendInfoMsg').val('')
                            }
                        } else {
                            _selectedIntentContent=''
                            $('#sendInfoMsg').val('')
                        }
                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.message
                        });
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            })
        }

        function getIntentNameByIntentKey(intentText){
            if(!intentText){
                return
            }
            const intentMap = [
                {text:'MERCHANDISE_OR_SERVICE_NOT_RECEIVED', label:'Item not received'},
                {text:'MERCHANDISE_OR_SERVICE_NOT_AS_DESCRIBED', label:'Item significantly not as described'},
                {text:'UNAUTHORISED', label:'Unauthorized transaction'},
                {text:'CREDIT_NOT_PROCESSED', label:'Missing refund or credit'},
                {text:'DUPLICATE_TRANSACTION', label:'Duplicate payment'},
                {text:'INCORRECT_AMOUNT', label:'Wrong amount or date'},
                {text:'PAYMENT_BY_OTHER_MEANS', label:'Paid with other method'},
                {text:'CANCELED_RECURRING_BILLING', label:'Cancelled preapproved payment'},
                {text:'CUSTOMER_SAID_ITEM_RETURNED', label:'Customer said item returned'},
                {text:'REFUND', label:'Refund'},
                {text:'OTHER', label:'Other'},
                {text:'ASK_WHICH_SKU_WANT_RETURN', label:'Ask_which_sku_want_return'}
            ]
            let _result = intentMap.filter(item => item.text == intentText.toLocaleUpperCase())
            if(_result.length>0){
                return _result[0].label
            }else{
                return '-'
            }
        }
    })

</script>